﻿using Architecture.Domain.Service;
using Architecture.Repository.Impl;
using Architecture.Repository.Interface;
using Architeture.Domain;
using Architeture.Domain.DTO;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC.ZhuBoLin.Application.Command.RoleCommand.RoleMenu;
using RBAC.ZhuBoLin.Application.Command.RoleCommand.RoleMenus;
using RBAC.ZhuBoLin.Dtos;

namespace RBAC.ZhuBoLin.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class RoleMenuController : ControllerBase
    {
        protected readonly IMediator mediator;
        protected readonly IRoleMneuService service;

        public RoleMenuController(IMediator mediator, IRoleMneuService service)
        {
            this.mediator = mediator;
            this.service = service;
        }


        /// <summary>
        /// 角色菜单添加
        /// </summary>
        /// <param name="cd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> RoleMenuAdd(RoleMenuCreateCommand cd)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await mediator.Send(cd);
            }
            catch (Exception ex)
            {
                result.Code = 1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns> 
        [HttpGet]
        public async Task<ApiResult<List<RoleMenuDTO>>> GetRoleId([FromQuery] RoleMenuSelectByidCommand sd)
        {
            ApiResult<List<RoleMenuDTO>> result = new ApiResult<List<RoleMenuDTO>>();
            try
            {
                result.Data = await mediator.Send(sd);
            }
            catch (Exception ex)
            {
                result.Code = 1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
    }
}
